/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-02-10
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-03-15
 * @Description: 
 */

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '/widgets/custom_global_widgets.dart';

import 'package:chat_client/providers/individual_provider.dart';

class IndividualScreen extends StatelessWidget {
  const IndividualScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Consumer<IndividualProvider>(
      builder: (context, model, child) {
        return Scaffold(
            appBar: AppBar(backgroundColor: Colors.white),
            body: ListView(children: [
              Container(
                padding: const EdgeInsets.only(
                    top: 0.0, bottom: 40.0, left: 16.0, right: 16.0),
                color: Colors.white,
                child: Row(
                  children: [
                    GestureDetector(
                      onTap: () => model.navToAvatar(),
                      // 头像
                      child:
                          SquareAvatar(imageSource: model.avatarUrl, size: 90),
                    ),
                    const SizedBox(width: 20), // 头像和文字之间的间隔
                    // 文字部分
                    Expanded(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(model.user.nickname,
                              style: Theme.of(context).textTheme.headlineLarge),
                          const SizedBox(height: 16),
                          Text('账号: ${model.user.username}'),
                        ],
                      ),
                    ),
                    // 右侧图标
                    const Icon(Icons.qr_code),
                    const SizedBox(width: 20), // 头像和文字之间的间隔
                  ],
                ),
              ),
              DividerWithText(
                thickness: 20,
                indent: 0,
                endIndent: 0,
              ),
              CListTile(
                icon: Icons.update,
                iconColor: const Color.fromARGB(255, 60, 203, 86),
                title: '更新资料',
                trailing: Icon(Icons.chevron_right),
                onTap: () => model.navToProfile(),
              ),
              DividerWithText(height: 1),
              CListTile(
                icon: Icons.settings,
                iconColor: Color.fromARGB(255, 90, 140, 255),
                title: '设置',
                trailing: Icon(Icons.chevron_right),
                onTap: () => model.navToSetting(),
              ),
              CListTile(
                icon: Icons.settings,
                iconColor: Color.fromARGB(255, 90, 140, 255),
                title: 'Hive可视化',
                trailing: Icon(Icons.chevron_right),
                onTap: () => model.navToHiveView(),
              ),
              CListTile(
                icon: Icons.clear_rounded,
                iconColor: Color.fromARGB(255, 90, 140, 255),
                title: '清理数据',
                onTap: () => model.clearHive(),
              ),
            ]));
      },
    );
  }
}
